package com.origin.onlinesys.service.modules.interviewsys.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.EnrollType;
import com.origin.onlinesys.persistence.modules.interviewsys.EnrollOriginMapper;
import com.origin.onlinesys.service.modules.interviewsys.IEnrollOriginService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/1/20.
 * 学生来源操作
 */
@Service
public class EnrollOriginServiceImpl  extends BaseService<EnrollType> implements IEnrollOriginService {
    /**
     * 插入新的数据
     * @param type
     * @return
     */
    public EnrollType insertEnrollType(EnrollType type){
        String id = this.checkHave(type.getName());
        type.setState("1");
        if(id == null){
            type.setId(this.save(type)+"");
        }else{
            type.setId(id);
            this.update(type);
        }
        return type;
    }

    /**
     * 删除来源
     * @param id
     * @return
     */
    public int deleteEnrollType(String id){
        EnrollType type = new EnrollType();
        type.setId(id+"");
        type.setState("2");
        return this.update(type);
    }

    /**
     * 修改来源
     * @param type 来源对象
     * @return
     */
    public int updateEnroll(EnrollType type){
        return this.update(type);
    }
    /**
     * 查询所有
     * @return
     */
    public List<EnrollType> selectAllEnrollTypes(){
        return this.queryAll();
    }

    /**
     * 根据条件查询
     * @param type 来源对象
     * @return
     */
    public List<EnrollType> selectByWhere(EnrollType type){
        return this.queryByWhere(type);
    }

    /**
     * 根据状态查询数据
     * @param state
     * @return
     */
    public List<EnrollType> selectByState(String state){
        return ((EnrollOriginMapper)mapper).selectByState(state);
    }

    /**
     * 根据ID查询数据
     * @param id id
     * @return
     */
    public EnrollType selectById(String id){
        EnrollType type =  new EnrollType();
        type.setId(id);
        return this.selectByWhere(type).get(0);
    }

    public String checkHave(String name) {
        return ((EnrollOriginMapper)mapper).checkHave(name);
    }
}
